package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description
 * @Author Fan Jiajun
 * @Date 2025年5月10日
 */

@Api(tags = "护理等级")
@RestController
@RequestMapping("/nursingLevel")
public class NursingLevelController extends BaseController{

    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有护理等级")
    public ResponseResult<NursingLevelVo> findAll(){
        List<NursingLevelVo> nursingLevelVos = nursingLevelService.findAll();
        return success(nursingLevelVos);
    }

    @GetMapping("/listByPage")
    @ApiOperation(value = "分页查询护理等级")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "护理等级名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "int", paramType = "query")
    })
    public ResponseResult<PageResponse<NursingLevelVo>> findByPage(
            @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Integer status){
        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.findByPage(pageNum, pageSize, name, status);
        return success(pageResponse);
    }

    @PostMapping("/insert")
    @ApiOperation(value = "添加护理等级")
    public ResponseResult add(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.add(nursingLevelDto);
        return success();
    }


    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理等级")
    public ResponseResult<NursingLevelVo> findById(@PathVariable Long id){
        NursingLevelVo nursingLevelVo = nursingLevelService.findById(id);
        return success(nursingLevelVo);
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新护理等级")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.update(nursingLevelDto);
        return success();
    }


    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除护理等级")
    public ResponseResult delete(@PathVariable Long id){
        nursingLevelService.delete(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "更新护理等级状态")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status){
        nursingLevelService.updateStatus(id, status);
        return success();
    }
}
